package matchthreegame.handlers;

import matchthreegame.extensions.MatchThreeGameRoomExtension;
import matchthreegame.extensions.MatchThreeGameZoneExtension;

import com.smartfoxserver.v2.entities.Room;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.extensions.BaseClientRequestHandler;

public class ReturnToLobbyRequestHandler extends BaseClientRequestHandler {

	MatchThreeGameZoneExtension zoneExtension;
	
	@Override
	public void handleClientRequest(User sender, ISFSObject params) {
		
		zoneExtension = (MatchThreeGameZoneExtension)getParentExtension().getParentZone().getExtension();
		
		String senderName = sender.getName();
		
		trace(senderName + " want to Join to LOBBY !" );
		
		Room gameRoom = sender.getLastJoinedRoom();
		
		if ( gameRoom.isGame() == true ) {
			
			MatchThreeGameRoomExtension roomExtension = (MatchThreeGameRoomExtension) gameRoom.getExtension();
			roomExtension.userLeftTheGame(sender.getId());
			
		}
		
		zoneExtension.joinUserToLobby(sender);
		
	}

}
